<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="static com.testtask.rightandabove.tools.Command.*"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type='text/javascript'>
            function validationFileSize() {
                var input, file, fileName;
                if (!window.FileReader) {
                    bodyAppend("p", "The file API isn't supported on this browser yet.");
                    return;
                }
                input = document.getElementById('fileinput');
                file = input.files[0];
                if (file.size > 1048576){
                    bodyAppend("p", "File must be less than 1 MB. " + "File size is: " + file.size + "bytes");
                    return false;
                }
                fileName = file.name;
                if((fileName.split('.').pop())!="xml"){
                    bodyAppend("p", "File extension must be *.xml");
                    return false;
                }
                return true;
            }

            function bodyAppend(tagName, innerHTML) {
                var elm;

                elm = document.createElement(tagName);
                elm.innerHTML = innerHTML;
                document.body.appendChild(elm);
            }
        </script>
        <title>Upload XML</title>
    </head>
    <body>
        <%@ include file="index.jsp" %> 
        <h2>Upload file</h2>
        <form:form commandName="<%=DATA_UPLOAD_COMMAND%>" method="post" enctype="multipart/form-data" onsubmit="return validationFileSize();">
            <table>
                <tbody>
                    <tr>
                        <td> <form:input path="fileData" type="file" id='fileinput'/></td>
                        <td> <form:errors style="color:red;" path="fileData" /><br /></td>
                    </tr>
                </tbody>
            </table>
            <input type="submit" value="Submit"/>
        </form:form>
    </body>
</html>
